"use strict";
module.exports = (app) => {
  const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  const Video = app.model.define("video", {
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
    },
    title: {
      type: TEXT,
      allowNull: false,
      comment: "视频标题",
    },
    url: {
      type: STRING(200),
      allowNull: false,
      comment: "视频地址",
    },
    cover: {
      type: STRING(200),
      allowNull: false,
      comment: "视频封面",
    },
    user_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      comment: "用户id",
      references: {
        model: "user",
        key: "id",
      },
      onUpdate: "restrict", // 更新时操作
      onDelete: "cascade", // 删除时操作
    },
    created_at: DATE,
    updated_at: DATE,
  });
  Video.associate = function (model) {
    Video.hasMany(app.model.VideoLikes, {
      foreignKey: "video_id",
    });
    Video.hasMany(app.model.VideoComment, {
      foreignKey: "video_id",
    });
    Video.belongsTo(app.model.User, {
      foreignKey: "user_id",
    });
  };
  return Video;
};
